﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class MyReg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        if (Session["Name"] == null)
        {
            Response.Write("<script>alert('你还没登录，请先登录账号！');window.location.href='Logon.aspx';</script>");
        }
        else
        {
            string date = DateTime.Now.ToString("yyyy - MM - dd");
            string ID = Session["Name"].ToString();
            string sql = string.Format("select * from Register INNER JOIN Scheduling ON Register.DocID = Scheduling.DocID AND Register.DauyDate = Scheduling.DauyDate where PatIDCard='{0}' and VisStatus='未就诊' and Register.DauyDate>='{1}' order by RegID", ID,date);
            DataSet set = DBHelper.GetDataSet(sql);
            GridView1.DataSource = set;
            GridView1.DataKeyNames = new string[] { "RegID" };
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
                e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确定要退号吗')");
                //高亮显示
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sql = string.Format("update Register set VisStatus='已退号' where Regid='{0}'", id);
        int n = DBHelper.GetNonQuery(sql);
        if (n <= 0)
        {
            Response.Write("<script>alert('退号失败！')</script>");
        }
        else 
        {
            Response.Write("<script>alert('退号成功！')</script>");
        }
        Bind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
}